import 'package:flutter/cupertino.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:zootix/util/zt_screen_adaper_util.dart';

class ZtRefreshHeader extends RefreshIndicator {
  ZtRefreshHeader()
      : super(
            height: ZtScreenAdaper.height(100),
            refreshStyle: RefreshStyle.Follow);
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return ZtRefreshHeaderState();
  }
}

class ZtRefreshHeaderState extends RefreshIndicatorState<ZtRefreshHeader>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }

  @override
  void onModeChange(RefreshStatus? mode) {
    super.onModeChange(mode);
  }

  @override
  Future<void> endRefresh() async {}

  @override
  void resetValue() {
    super.resetValue();
  }

  @override
  Widget buildContent(BuildContext context, RefreshStatus mode) {
    TextStyle style = TextStyle(fontSize: ZtScreenAdaper.sp(18));
    Widget body;
    if (mode == RefreshStatus.refreshing) {
      body = const CupertinoActivityIndicator();
    } else if (mode == RefreshStatus.canRefresh) {
      body = const CupertinoActivityIndicator(animating: false);
    } else if (mode == RefreshStatus.completed) {
      body = const SizedBox();
    } else if (mode == RefreshStatus.failed) {
      body = Text("No more Data)", style: style);
    } else {
      body = const CupertinoActivityIndicator();
    }
    return SizedBox(
      height: ZtScreenAdaper.height(40),
      child: Center(child: body),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
